  
package com.xebest.web.service.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xebest.web.form.XeVenFinPurchPayForm;
import com.xebest.web.mapper.read.XeVenFinPurchPayReadMapper;
import com.xebest.web.mapper.write.XeVenFinPurchPayWriteMapper;
import com.xebest.web.model.XeVenFinPurchPayDetailEntity;
import com.xebest.web.model.XeVenFinPurchPayEntity;
import com.xebest.web.service.XeVenFinPurchPayReadService;
import com.xebest.web.view.XeVenFinPurchPayView;

/**
 * 付款单service
 * @desc: xebest-erp  
 * @author: 赵盼飞  
 * @createTime: 2017年8月2日 下午2:02:04  
 * @history:  
 * @version: v1.0
 */
@Service
public class XeVenFinPurchPayServiceImpl implements XeVenFinPurchPayReadService {

	@Autowired
	private XeVenFinPurchPayReadMapper finPurchPayReadMapper;//付款单读
	
	@Autowired
	private XeVenFinPurchPayWriteMapper finPurchPayWriteMapper;//付款单写
	
	@Override
	@Transactional(value="writeTransactionManager")
	public int insertFinPurchPay(XeVenFinPurchPayEntity finPurchPay) {
		  
		return finPurchPayWriteMapper.insertFinPurchPay(finPurchPay);  
		
	}

	@Override
	@Transactional(value="writeTransactionManager")
	public int updateXeVenFinPurchPayByPSettleCode(XeVenFinPurchPayEntity finPurchPay) {
		  
		return finPurchPayWriteMapper.updateXeVenFinPurchPayByPSettleCode(finPurchPay);  
		
	}

	@Override
	@Transactional(value="writeTransactionManager")
	public int insertFinPurchPayDetail(XeVenFinPurchPayDetailEntity finPurchPayDetail) {
		  
		return finPurchPayWriteMapper.insertFinPurchPayDetail(finPurchPayDetail);  
		
	}

	@Override
	@Transactional(value="writeTransactionManager")
	public int updateFinPurchPayDetailByPSettleCode(XeVenFinPurchPayDetailEntity finPurchPayDetail) {
		  
		return finPurchPayWriteMapper.updateFinPurchPayDetailByPSettleCode(finPurchPayDetail);  
		
	}

	@Override
	@Transactional(value="writeTransactionManager")
	public int insertBatchFinPurchPayDetail(List<XeVenFinPurchPayDetailEntity> finPurchPayDetailList) {
		  
		return finPurchPayWriteMapper.insertBatchFinPurchPayDetail(finPurchPayDetailList);  
		
	}

	@Override
	public List<XeVenFinPurchPayView> queryXeVenFinPurchPayFormList(XeVenFinPurchPayForm form) {
		  
		List<XeVenFinPurchPayView> finPayList = finPurchPayReadMapper.queryXeVenFinPurchPayFormList(form);
		return finPayList;  
		
	}

	@Override
	@Transactional(value="writeTransactionManager")
	public int insertBatchFinPurchPay(List<XeVenFinPurchPayEntity> finPurchPayList) {
		  
		return finPurchPayWriteMapper.insertBatchFinPurchPay(finPurchPayList);  
		
	}

	@Override
	public List<XeVenFinPurchPayView> queryFinPurchPayDetail(XeVenFinPurchPayForm form) {
		  
		return finPurchPayReadMapper.queryFinPurchPayDetail(form);  
		
	}

	@Override
	public int updateFinPurchPayByOrderId(XeVenFinPurchPayEntity finPurchPayEntity) {
		  
		return finPurchPayWriteMapper.updateFinPurchPayByOrderId(finPurchPayEntity);  
		
	}

	@Override
	public Map<String, Object> queryXeSysFinPayBill(Map<String, Object> paraMap) {
		  
		return finPurchPayReadMapper.queryXeSysFinPayBill(paraMap);  
		
	}

	@Override
	public List<Map<String, Object>> queryXeSysFinPayBillDetailList(Map<String, Object> paraDetailMap) {
		  
		return finPurchPayReadMapper.queryXeSysFinPayBillDetailList(paraDetailMap);  
		
	}

	@Override
	public List<Map<String, Object>> querysupNameList(String userCode) {
		  
		return finPurchPayReadMapper.querysupNameList(userCode);  
		
	}

	@Override
	public int updateBathFinPurchPayByPsettleCodeArr(XeVenFinPurchPayForm pform) {
		XeVenFinPurchPayEntity en = new XeVenFinPurchPayEntity();
		if(pform.getPsettleCodeArr().length>0){
			en.setpSettleCodeList(Arrays.asList(pform.getPsettleCodeArr()));
		}else{
			en.setpSettleCodeList(pform.getpSettleCodeList());
		}
		if(pform.getStartSettleDate()!=null){
			en.setStartSettleDate(new Date());
		}
		en.setSettleAccountsAmount(pform.getSettleAccountsAmount());
		en.setUserCode(pform.getUserCode());
		en.setpSettleStatus(2);
		en.setSelfSettleCode(pform.getSelfSettleCode());
		return finPurchPayWriteMapper.updateBathFinPurchPayByPsettleCodeArr(en);  
		
	}
	
}
  
